// 路由文件

import VueRouter from "vue-router"
import home from './components/main/home.vue'
import search from './components/main/search.vue'
import member from './components/main/member.vue'
import shopcar from './components/main/shop.vue'
import douban from './components/sub/moive.vue'
import moiveinfo from './components/sub/moiveinfo.vue'
import newlist from './components/sub/newlist.vue'
import newinfo from './components/sub/newinfo.vue'
import comments from './components/sub/comments.vue'
import goodslist from './components/sub/shoplist.vue'
import goodsinfo from './components/sub/shopinfo.vue'
import goodsmain from './components/sub/shopinfo-m.vue'
import tukulist from './components/sub/tukulist.vue'
import tukuinfo from './components/sub/tukuinfo.vue'

// 导入路由组件
var  router = new VueRouter({
    routes:[
        {path:'/',redirect:'/home'},
        {path:'/home',component:home},
        {path:'/member',component:member},
        {path:'/shopcar',component: shopcar},
        {path:'/search',component: search},
        {path:'/home/douban',component:douban},
        {path:'/home/douban/movieinfo/:id',component:moiveinfo},
        {path:'/home/douban/movieinfo/:id',component:moiveinfo},
        {path:'/home/newlist',component:newlist},
        {path:'/home/newlist/newinfo/:id',component:newinfo},
        {path:'/home/newlist/comments/:id',component:comments},
        {path:'/home/goodslist',component:goodslist},
        {path:'/home/goodslist/goodsinfo/:id',component:goodsinfo},
        {path:'/home/goodslist/goodsinfo-m/:id',component:goodsmain},
        {path:'/home/tuku',component:tukulist},
        {path:'/home/tukuinfo/:id',component:tukuinfo}
    ],
    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {        
            return savedPosition    
        } else {      
            if (from.meta.keepAlive) {        
                from.meta.savedPosition = document.body.scrollTop;      
            }        
            return { x: 0, y: to.meta.savedPosition || 0 }    
        }  
    }
})

export default router